package com.lkk.cg.service.impl;

import com.lkk.cg.base.DaoSupportImpl;
import com.lkk.cg.domain.User;
import com.lkk.cg.service.UserService;
import org.apache.commons.codec.digest.DigestUtils;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by lkk on 2014/12/1.
 */
@Transactional
//@Service
public class UserServiceImpl extends DaoSupportImpl<User> implements UserService {

    public void initPassword(Long id) {
        User user = getById(id);
        user.setPassword(DigestUtils.md5Hex("123456"));
        update(user);
    }

    public User getByLoginName(String loginName) {
        Session session = getSession();
        Query query = session.createQuery("from " + clazz.getSimpleName() + " u where u.loginName = ?")
                .setParameter(0, loginName);
        return (User) query.uniqueResult();
    }

}
